import {Component, ViewChild,} from '@angular/core';
import {Modal, ModalController, NavController, NavParams} from 'ionic-angular';

import {HomePage} from '../home/home';
import {MyPage} from "../my/my";
import {ApplyTabPage} from "../apply/apply-tab/apply-tab";
import {ToDoApprovalPage} from "../home/to-do-approval/to-do-approval";
import {ApplyStoreSLS} from "../apply/applyStoreSLS";
import {ToolsTabPage} from "../tools-tab/tools-tab";
import { IndexQueryPage } from '../index-query/index-query';
import {Tabs} from "ionic-angular";
@Component({
    selector: 'page-tabs',
    templateUrl: 'tabs.html'
})
export class TabsPage {

    tab1Root = HomePage;// 首页
    tab2Root = ToDoApprovalPage;// 待办审批
    tab3Root = IndexQueryPage;// ApplyTabPage;// 报销申请
    tab4Root = MyPage;// 我的
    tab5Root = ToolsTabPage;
    tab1Icon: string = "tab1iconSelected";
    tab2Icon: string = "tab2icon";
    tab3Icon: string = "tab3icon";
    tab4Icon: string = "tab4icon";
    private profileModal:Modal = null;
    @ViewChild('mainTabs') tabs:Tabs;
    constructor(public navCtrl: NavController,public modalCtrl: ModalController ) {

    }

    tabSelected(selectedIndex: number) {
        //全部初始化
        this.tab1Icon = "tab1icon";
        this.tab2Icon = "tab2icon";
        this.tab3Icon = "tab3icon";
        this.tab4Icon = "tab4icon";
        switch (selectedIndex) {
            case 0:
                this.tab1Icon = "tab1iconSelected";
                break;
            case 1:
                this.tab2Icon = "tab2iconSelected";
                break;
            case 2:
                ApplyStoreSLS.getInstance().destroy();//编辑申请单时由于保存了一份数据，切换tab时把原始数据销毁
                this.tab3Icon = "tab3iconSelected";
                break;
            case 3:
                this.tab4Icon = "tab4iconSelected";
                break;
            case 4:
                break;
        }
    }
    tab5(){
        this.tab1Icon = "tab1icon";
        this.tab2Icon = "tab2icon";
        this.tab3Icon = "tab3icon";
        this.tab4Icon = "tab4icon";
        //this.navCtrl.push(ToolsTabPage)
        if(this.profileModal) {
            return;
        }
        this.profileModal = this.modalCtrl.create(ToolsTabPage);
        this.profileModal.onDidDismiss(async (data) => {
            this.profileModal = null;
        });
        this.profileModal.present();
    }
}
